<?php
namespace app\behavior;
use think\Controller;

class CheckLogin extends Controller{

  //免验证控制器
  private $notCheckController = [
    'Index',
  ];

  //免验证方法
  private $notCheckFunction = [
    'Admin.trumpet.line2',
  ];

  public function checkLogin(){
    $current_controller = request()->controller();
    $current_function = request()->controller().'.'.request()->action();
    if(!in_array($current_controller,$this->notCheckController)
      && !in_array($current_function,$this->notCheckFunction)){
      //验证start
      if(session('?userID') && session('?userInfo') && time()-session('refreshTime')<1800){
        session('refreshTime',time());
        $check = true;
      }else{
        $check = false;
      }
      //验证end
      if($check == false){
        $this->redirect('/login');
      }
    }
  }


}//END